From 5ab30725b1736b3af47ad911b800a8fbcbd6a112 Mon Sep 17 00:00:00 2001 From: Andre Przywara Date: Fri, 10 Sep 2010 18:57:28 +0100 Subject: [PATCH] xl: fix adding configuration parameters on command line Since we read the text file as is from the disk, there is no trailing \0 at the end terminating the C string. Therefore we must not use strcat to this buffer. Also we need to allocate space for the trailing zero byte. Signed-off-by: Andre Przywara Signed-off-by: Ian Jackson --- tools/libxl/xl_cmdimpl.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/tools/libxl/xl_cmdimpl.c b/tools/libxl/xl_cmdimpl.c index 3cd310e09e..6e2fce786d 100644 --- a/tools/libxl/xl_cmdimpl.c +++ b/tools/libxl/xl_cmdimpl.c @@ -1315,22 +1315,20 @@ static int create_domain(struct domain_create *dom_info) &config_data, &config_len); if (ret) { fprintf(stderr, "Failed to read config file: %s: %s\n", config_file, strerror(errno)); return ERROR_FAIL; } - if (!restore_file && extra_config - && strlen(extra_config)) { - if (config_len > INT_MAX - (strlen(extra_config) + 2)) { + if (!restore_file && extra_config && strlen(extra_config)) { + if (config_len > INT_MAX - (strlen(extra_config) + 2 + 1)) { fprintf(stderr, "Failed to attach extra configration\n"); return ERROR_FAIL; } + /* allocate space for the extra config plus two EOLs plus \0 */ config_data = realloc(config_data, config_len - + strlen(extra_config) + 2); + + strlen(extra_config) + 2 + 1); if (!config_data) { fprintf(stderr, "Failed to realloc config_data\n"); return ERROR_FAIL; } - strcat(config_data, "\n"); - strcat(config_data, extra_config); - strcat(config_data, "\n"); - config_len += (strlen(extra_config) + 2); + config_len += sprintf(config_data + config_len, "\n%s\n", + extra_config); } } else { if (!config_data) { -- 2.30.2